﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Common
{
	public class Forum:IEnumerable<ForumMessage>
	{
		public string Name;
		public string Url;
		public List<ForumMessage> Messages;
		public Forum()
		{
			Name = Url = string.Empty;
			Messages = new List<ForumMessage>();
		}

		#region IEnumerable<ForumMessage> Members

		public IEnumerator<ForumMessage> GetEnumerator()
		{
			return Messages.GetEnumerator();
		}

		#endregion

		#region IEnumerable Members

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return Messages.GetEnumerator();
		}

		#endregion
	}
	public class ForumMessageInfo
	{
		public DateTime Date;
		public string Link;
		public string OriginalLink;
		public ForumMessageInfo(DateTime date, string link)
		{
			Date = date;
			Link = link;
		}
		public override string ToString()
		{
			return Date.ToString() +" "+ Link;
		}
	}
	public class ForumMessage : Content
	{
		public long UniqueId;
		string _text, _topic, _author;
		public string Text { get { return _text; } set { _text = StripHtmlCode(value); } }
		public string Topic { get { return _topic; } set { _topic = StripHtmlCode(value); } }
		public string Author { get { return _author; } set { _author = StripHtmlCode(value); } }
		public DateTime Date;

		public static string[] toRemove = { "<br>", "<b>", "</b>" };
		public static Hashtable toReplace = new Hashtable() 
		{ { "&quot;", "\"" }, { "&gt;", ">" }, { "&lt;", "<" }, { "&amp;", "&" }, { "&#39", "'" }, {"&nbsp;", " "} };

		private static string StripHtmlCode(string input)
		{
			return input;
		}

		public ForumMessage()
		{
			Text = Topic = Author = string.Empty;
			Date = new DateTime();
		}

		public ForumMessage(string topic, string text, string author, DateTime date)
		{
			Topic = topic;
			Text = text;
			Author = author;
			Date = date;
		}

        public ForumMessage(Talkback talkback)
        {
            Topic = talkback.Title;
            Text = talkback.Text;
            Author = talkback.Author;
            Date = talkback.DateTime;
            SiteName = talkback.SiteName;
            Uri = talkback.Uri;
            UniqueId = talkback.ID;
        }
		public override string ToString()
		{
			return string.Format("{0} {1}", UniqueId, Topic);
		}
	}
}
